home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Standard Catalog Package / DTS AddressOMatic / Src / AOMCreateButtons.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  3.5 KB  |  149 lines  |  [TEXT/KAHL]

  1. /*                                AOMCreateButtons.c                                */
  2. /*
  3.  * AddressOMatic Sample
  4.  * AOMCreatePanels.c
  5.  * Copyright © 1993 Apple Computer Inc. All rights reserved.
  6.  */
  7. #include "AddressOMaticPrivate.h"
  8.  
  9. const AOMRadioButton        _AOMRadioInfo[kAOMRadioButtons] = {
  10.     { kAOMEnablePDBit,        kAOMPDRadioButton,        kAOMPDRadioSelect        },
  11.     { kAOMEnablePanelBit,    kAOMPanelRadioButton,    kAOMPanelRadioSelect    },
  12.     { kAOMEnableFindBit,    kAOMFindRadioButton,    kAOMFindRadioSelect        }
  13. #ifdef ENABLE_TYPEIN
  14.     ,
  15.     { kAOMEnableTypeInBit,    kAOMTypeInRadioButton,    kAOMTypeInRadioSelect    }
  16. #endif
  17. };
  18.  
  19. /*
  20.  * This is used to construct a color spec. It could be moved to a 'cctb'
  21.  * resource but that would require avoiding application resources.
  22.  */
  23. static const CtlCTab            gCCTable = {
  24.         0, 0, 3,
  25.         cFrameColor,    kAOMBlackColor,
  26.         cBodyColor,        kAOMBackgroundColor,
  27.         cTextColor,        kAOMBlackColor,
  28.         cFrameColor,    kAOMBlackColor
  29.     };
  30.  
  31. OSErr                            _AOMMakeButton(
  32.         register AddressOMaticPtr    aomPtr,
  33.         AOMItemIndex                titleString,
  34.         ControlHandle                *theControlPtr
  35.     );
  36. void                            _AOMSetControlColor(
  37.         ControlHandle                theControl
  38.     );
  39.  
  40. OSErr
  41. _AOMCreateButtons(
  42.         register AddressOMaticPtr    aomPtr,
  43.         AOMModeMask                    enableModeMask
  44.     )
  45. {
  46.         OSErr                        status;
  47.         short                        i;
  48.         
  49.         /*
  50.          * Build the AddressOMatic panel action buttons.
  51.          */
  52.         _AOMSetFont(aomPtr, kAOMLabelFontStyle);
  53.         status = noErr;
  54.         if ((enableModeMask & kAOMShowDoneButtonMask) != 0) {
  55.             status = _AOMMakeButton(
  56.                         aomPtr,
  57.                         kAOMDoneButtonString,
  58.                         &AOM.doneButton
  59.                     );
  60.         }
  61.         if (status == noErr
  62.          && (enableModeMask & kAOMShowCCButtonMask) != 0) {
  63.             status = _AOMMakeButton(
  64.                     aomPtr,
  65.                     kAOMCCButtonString,
  66.                     &AOM.ccButton
  67.                 );
  68.         }
  69.         if (status == noErr
  70.          && (enableModeMask & kAOMShowToButtonMask) != 0) {
  71.             status = _AOMMakeButton(
  72.                     aomPtr,
  73.                     kAOMToButtonString,
  74.                     &AOM.toButton
  75.                 );
  76.         }
  77.         /*
  78.          * Enable the enabled radio buttons.
  79.          */
  80.         for (i = 0; i < kAOMRadioButtons; i++) {
  81.             if ((enableModeMask & (1L << (i + kAOMEnablePDBit))) != 0)
  82.                 AOM.radioEnable[i] = TRUE;
  83.         }
  84.         return (status);
  85. }
  86.  
  87. OSErr
  88. _AOMMakeButton(
  89.         register AddressOMaticPtr    aomPtr,
  90.         AOMItemIndex                titleString,
  91.         ControlHandle                *theControlPtr
  92.     )
  93. {
  94.         OSErr                        status;
  95.         Rect                        dummyRect;
  96.         Str255                        title;
  97.         
  98.         SetRect(&dummyRect, 0, 0, 0, 0);
  99.         GetIndString(title, AOM.stringsResID, titleString);
  100.         *theControlPtr = NewControl(
  101.                     AOM.window,                /* Control is in this window    */
  102.                     &dummyRect,                /* Will be reset by decorator    */
  103.                     title,                    /* Control label text            */
  104.                     FALSE,                    /* Invisible (decorator fixes)    */
  105.                     0, 0, 1,                /* Values                        */
  106.                     (pushButProc | useWFont), /* Normal button, our font    */
  107.                     0                        /* No refCon (yet)                */
  108.                 );
  109.         if (*theControlPtr == NULL)
  110.             status = MemError();
  111.         else {
  112.             status = noErr;
  113.             if (IS_COLOR(AOM.window))
  114.                 _AOMSetControlColor(*theControlPtr);
  115.         }
  116.         LOG(status, "\p_AOMMakeButton");
  117.         return (status);
  118. }
  119.     
  120. /*
  121.  * This creates a control table color record the first time it's called,
  122.  * but does nothing for subsequent calls (as the table's been created).
  123.  * Only memory errors are possible.
  124.  */
  125. void
  126. _AOMSetControlColor(
  127.         ControlHandle                theControl
  128.     )
  129. {
  130.         OSErr                    status;
  131.         CCTabHandle                colorHandle;
  132.             
  133.         /*
  134.          * The default CtlCTab has space for four ColorSpec's, but
  135.          * we only use three. However, something in the system
  136.          * looks at the fourth Grrr.
  137.          */
  138.         status = PtrToHand(
  139.                     (Ptr) &gCCTable,
  140.                     (Handle *) &colorHandle,
  141.                     sizeof (CtlCTab)
  142.                 );
  143.         if (status == noErr)
  144.             SetCtlColor(theControl, colorHandle);
  145.         LOG(status, "\p_AOMSetControlColor (ignored)");
  146. }
  147.  
  148.  
  149.